package com.cn.byjk.Controller;

import com.cn.byjk.service.ForeignSerice;
import com.cn.byjk.service.FundService;
import com.cn.byjk.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;

@RestController
@RequestMapping("/view")
public class AssetsViewController {
    @Autowired
    RestTemplate restTemplate;

    @Value("${service-url.foreign-url}")
    private String foreignUrl;

    @Value("${service-url.fund-url}")
    private String fundUrl;

    @Value("${service-url.manage-url}")
    private String manageUrl;
    @Autowired
    private ForeignSerice foreignSerice;

    @Autowired
    private FundService fundService;

    @Autowired
    private ManageService manageService;

    @GetMapping("/getMoney")
    public Double getMoney(Long id){
/*        BigDecimal foreign = restTemplate.getForObject(foreignUrl+"/foreign/getMoney?userid="+id,BigDecimal.class);
        BigDecimal fund = restTemplate.getForObject(fundUrl+"/fund/getMoney?userid="+id,BigDecimal.class);
        BigDecimal manage = restTemplate.getForObject(manageUrl+"/manage/getMoney?userid="+id,BigDecimal.class);*/

        BigDecimal fund = fundService.getMoney(id);
        BigDecimal foreign = foreignSerice.getMoney(id);

        BigDecimal manage = manageService.getMoney(id);
        BigDecimal result = foreign.add(fund).add(manage);
        return result.doubleValue();
    }
}
